package com.lyc.qy158springbootredis;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@SpringBootTest
class Qy158SpringbootRedisApplicationTests02 {

    //该类中封装了很多api方法--redis服务
    @Autowired
    private RedisTemplate redisTemplate;

    //关于key操作的方法。
    @Test
    void contextLoads() {
        //默认RedisTemplate它的key和value的序列化都是使用的JdkSerializationRedisSerializer方式，该序列化要求类必须实现Serializable接口。

        //我们在实际开发中，我们的key都是String类型，我们应该指定String序列化方式
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("k8",new Student("小晨晨",16,"男"));
        System.out.println(valueOperations.get("k8"));

    }
    @Test
    public void test01(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("k10",new Student("哈哈",16,"男"));
        System.out.println(valueOperations.get("k10"));
    }

}
